package com.wnxy.pawnbackgroundsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.wnxy.pawnbackgroundsystem.dto.ShopDefineDto;
import com.wnxy.pawnbackgroundsystem.entity.ShopDefine;
import com.wnxy.pawnbackgroundsystem.dao.ShopDefineMapper;
import com.wnxy.pawnbackgroundsystem.service.IShopDefineService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 商品鉴定图定义表 服务实现类
 * </p>
 *
 * @author Lucas
 * @since 2021-10-14
 */
@Service
public class ShopDefineServiceImpl extends ServiceImpl<ShopDefineMapper, ShopDefine> implements IShopDefineService {
    //条件查询鉴定图定义
    public List<ShopDefineDto> getShopDefine(Integer sortId){

        List<ShopDefine> shopDefines = null;
        ArrayList<ShopDefineDto> shopDefineDtos = new ArrayList<>();

        if(sortId==0){
            ShopDefine shopDefine = new ShopDefine();
            shopDefine.setDefineName("正面");
            shopDefine.setDefineStatus(0);
            shopDefine.setSortId(-1);
            this.save(shopDefine);

            shopDefine.setDefineName("侧面");
            shopDefine.setDefineStatus(1);
            this.save(shopDefine);

            shopDefine.setDefineName("背面");
            this.save(shopDefine);

            shopDefines = this.list(new QueryWrapper<ShopDefine>().eq("sort_id", -1));
            for(ShopDefine sd:shopDefines){
                ShopDefineDto shopDefineDto = new ShopDefineDto();
                BeanUtils.copyProperties(sd,shopDefineDto);
                shopDefineDtos.add(shopDefineDto);
            }
        }else {
            shopDefines = this.list(new QueryWrapper<ShopDefine>().eq("sort_id", sortId));
            for(ShopDefine sd:shopDefines){
                ShopDefineDto shopDefineDto = new ShopDefineDto();
                BeanUtils.copyProperties(sd,shopDefineDto);
                shopDefineDtos.add(shopDefineDto);
            }
        }

        return shopDefineDtos;
    }
    //删除鉴定图定义
    public void delShopDefine(Integer defineId){
        this.removeById(defineId);
    }
    //删除临时鉴定图定义
    public void delTimeDefine(){
        this.remove(new UpdateWrapper<ShopDefine>().eq("sort_id",-1));
    }
}
